#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int ans = 0;
        int prevMin = INT_MAX;
        for (int i = 0; i < prices.size(); i++)
        {
            ans = max(prices[i] - prevMin, ans);
            prevMin = min(prevMin, prices[i]);
        }
        return ans;
    }
};